package com.ning.activitys.skysound.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.toolbox.NetworkImageView;
import com.ning.activitys.skysound.R;
import com.ning.activitys.skysound.beans.GsonRadio;
import com.ning.activitys.skysound.fragment.musicpavilion.RadioFragment;
import com.ning.activitys.skysound.volley.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 16/1/26.
 */
public class MyGridViewAdapter extends BaseAdapter{

    private Context context;
    private List <GsonRadio.DataEntity.DataEntity1> childDate;

    public MyGridViewAdapter(Context context,List <GsonRadio.DataEntity.DataEntity1> childDate){

        this.context = context;
        this.childDate = childDate;
    }


    @Override
    public int getCount() {
        return childDate.size();
    }

    @Override
    public Object getItem(int position) {
        return 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ChildViewHolder childViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_rv_child_radio, parent, false);
            childViewHolder = new ChildViewHolder(convertView);
            convertView.setTag(childViewHolder);
        } else {
            childViewHolder = (ChildViewHolder) convertView.getTag();
        }

        VolleySingleton.getInstance().loadImage(childViewHolder.childImage,childDate.get(position).getLarge_pic_url());
        childViewHolder.radioSongSizeChild.setText(childDate.get(position).getQuantity() + "");
        childViewHolder.radioSongTypeChild.setText(childDate.get(position).getTag_name());

        return convertView;
    }


    private class ChildViewHolder {
        private NetworkImageView childImage;
        private TextView radioSongTypeChild,radioSongSizeChild;

        public ChildViewHolder(View view) {

            childImage = (NetworkImageView) view.findViewById(R.id.iv_rv_child_image_radio);
            radioSongSizeChild = (TextView) view.findViewById(R.id.tv_radio_song_size);
            radioSongTypeChild = (TextView) view.findViewById(R.id.tv_radio_song_type);
        }

    }

}
